package org.example.shop.service;

import org.example.shop.entity.Admin;
import org.example.shop.mapper.AdminMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.DigestUtils;

@Service
public class AdminService {
    @Autowired
    private AdminMapper adminMapper;

    public Admin login(String account, String password) {
        Admin admin = adminMapper.getAdminByAccount(account);
        if (admin != null) {
            String encryptedPassword = DigestUtils.md5DigestAsHex(password.getBytes());
            if (admin.getPassword().equals(encryptedPassword)) {
                return admin;
            }
        }
        return null;
    }
}